import { useEffect, useState } from "react";
import { initEditGlobalData } from "./editInit";

const useInitEditorGlobalData = () => {
	const [panelConfig, setPanelConfig] = useState([]);
	const [gEditorConfig, setGEditorConfig] = useState({});

	const initData = () => {
		// 初始化编辑器数据
		const { panelConfig, globalEditorData } = initEditGlobalData();
		// console.log(panelConfig, globalEditorData);
		setPanelConfig(panelConfig);
		setGEditorConfig(globalEditorData);
	};

	// 全局初始化入口
	useEffect(() => {
		if (JSON.stringify(gEditorConfig) === "{}") initData();
	}, [gEditorConfig]);

	return {
		panelConfig,
		gEditorConfig
	};
};

export { useInitEditorGlobalData };
